package com.sky.controller.user;

import com.sky.constant.RedisConstant;
import com.sky.dto.SetmealDTO;
import com.sky.entity.Setmeal;
import com.sky.entity.SetmealDish;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealOverViewVO;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户套餐
 */
@Api(tags = "用户套餐管理")
@RestController("UserSetmealController")
@RequestMapping("/user/setmeal")
public class SetmealController {

    private static final Logger log = LoggerFactory.getLogger(SetmealController.class);

    @Autowired
    private SetmealService setmealService;
    /**
     * 查询套餐内菜品
     * @param id
     * @return
     */
    @ApiOperation("查询套餐内菜品")
    @GetMapping("/dish/{id}")
    //由于此处加了缓存，会导致菜品也需要加对于缓存，但已经有了编码的缓存，担心会有冲突，所以此处不加缓存
    //@Cacheable(value = RedisConstant.SHOP_SETMEAL_DISH,key = "#id")
    public Result<List<DishItemVO>> queryBySetmealWithDish(@PathVariable("id") Long id) {
        log.info("查询套餐内菜品：{}",id);
        return setmealService.queryBySetmealWithDish(id);
    }

    /**
     * 分类id查询套餐
     * @return
     */
    @ApiOperation("分类id查询套餐")
    @GetMapping("/list")
    @Cacheable(cacheNames = RedisConstant.SHOP_CATEGORY_SETMEAL,key = "#categoryId")
    public Result<List<Setmeal>> querySetmealList(@RequestParam("categoryId") Integer categoryId){
        log.info("分类id查询套餐");
        return setmealService.querySetmealList(categoryId);
    }

}
